package com.erp.gather.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import com.erp.gather.domain.bo.ErpCollectAbsentSkuBo;
import com.erp.gather.domain.vo.ErpCollectAbsentSkuVo;
import com.erp.gather.service.IErpCollectAbsentSkuService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.gather.api.domain.ErpCollectAbsentSku;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * erp不存在的sku
 *
 * @author erp
 * @date 2023-05-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/collectAbsentSku")
public class ErpCollectAbsentSkuController extends BaseController {

    private final IErpCollectAbsentSkuService iErpCollectAbsentSkuService;

    /**
     * 根据条件查询不存在的sku
     * @param skuCode
     * @return
     */
    @GetMapping("/getBySkuCode/{skuCode}")
    public ErpCollectAbsentSku getBySkuCode(@PathVariable String skuCode) {
        return iErpCollectAbsentSkuService.getBySkuCode(skuCode);
    }

    /**
     * 新增erp不存在的sku
     */
    @PostMapping("/addSku")
    public R<Void> addSku(@RequestBody ErpCollectAbsentSku collectAbsentSku) {
        ErpCollectAbsentSkuBo add = BeanUtil.toBean(collectAbsentSku, ErpCollectAbsentSkuBo.class);
        add.setStatus("0");
        return toAjax(iErpCollectAbsentSkuService.insertByBo(add));
    }
    /**
     * 查询erp不存在的sku列表
     */
    @SaCheckPermission("system:collectAbsentSku:list")
    @GetMapping("/list")
    public TableDataInfo<ErpCollectAbsentSku> list(ErpCollectAbsentSkuBo bo, PageQuery pageQuery) {
        return iErpCollectAbsentSkuService.queryPageList(bo, pageQuery);
    }

    /**
     * 修改采集状态
     */
//    @PostMapping("/setStatus")
//    public R<Void> setStatus(@RequestBody ErpCollectAbsentSkuBo bo) {
//        Long id = bo.getId();
//        ErpCollectAbsentSkuVo absentSkuVo = iErpCollectAbsentSkuService.queryById(id);
//        absentSkuVo.setStatus("1");
//
//        return toAjax(iErpCollectAbsentSkuService.updateByBo(BeanUtil.toBean(absentSkuVo, ErpCollectAbsentSkuBo.class)));
//    }


    /**
     * 获取erp不存在的sku详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:collectAbsentSku:query")
    @GetMapping("/{id}")
    public R<ErpCollectAbsentSkuVo> getInfo(@NotNull(message = "主键不能为空")
                                            @PathVariable Long id) {
        return R.ok(iErpCollectAbsentSkuService.queryById(id));
    }

    /**
     * 新增erp不存在的sku
     */
    @PostMapping("/add")
    public R<Void> add(@RequestBody ErpCollectAbsentSkuBo bo) {
        bo.setStatus("0");
        return toAjax(iErpCollectAbsentSkuService.insertByBo(bo));
    }

    /**
     * 修改erp不存在的sku
     */
//    @SaCheckPermission("system:collectAbsentSku:edit")
//    @Log(title = "erp不存在的sku", businessType = BusinessType.UPDATE)
//    @RepeatSubmit()
//    @PutMapping()
//    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpCollectAbsentSkuBo bo) {
//        return toAjax(iErpCollectAbsentSkuService.updateByBo(bo));
//    }

    /**
     * 删除erp不存在的sku
     */
    @SaCheckPermission("system:collectAbsentSku:remove")
    @Log(title = "erp不存在的sku", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public R<Void> remove(Long id) {
        List<Long> list = new ArrayList<>();
        list.add(id);
        return toAjax(iErpCollectAbsentSkuService.deleteWithValidByIds(list, false));
    }
}
